from PIL import Image,ImageGrab, ImageChops
import re
import configparser
import shutil

conf=configparser.ConfigParser()
conf.read('config.ini',encoding='utf-8')
rectnum=int(conf.get('rects','rectnum'))
rect_1=conf.get('rects','rect_1')
rect_2=conf.get('rects','rect_2')
rect_3=conf.get('rects','rect_3')
rect_4=conf.get('rects','rect_4')
rect_5=conf.get('rects','rect_5')
rect_6=conf.get('rects','rect_6')
rect_7=conf.get('rects','rect_7')
rect_8=conf.get('rects','rect_8')
rect_9=conf.get('rects','rect_9')
rect_10=conf.get('rects','rect_10')

# 截取整个屏幕待用
imgroot = ImageGrab.grab()
imgroot.save("cropimages\\root.png")
print("start deploy rect_base&init.png......")
with open("status\\0_status.txt", 'w') as f:
    f.write('0')
for i in range(1, 11):
    shutil.copy("status\\0_status.txt","status\\"+str(i)+"_status.txt")
for i in range(1, rectnum + 1):
    print("rect", i, "----", locals()['rect_' + str(i)])
    xys = re.split(r'[^0-9]+',locals()['rect_' + str(i)])
    xy = list(map(int, xys))
    imgi = imgroot.crop((xy[2], xy[3], xy[2] + xy[0], xy[3] + xy[1]))
    imgi.save("cropimages\\"+str(i) + "_base.png")
    imgi.save("cropimages\\"+str(i) + "_init.png")
print("done deploy rect_base&init.png......")